
<%@ page import="auctionhaus.Listing" %>
<!doctype html>
<html>
	<head>
		<meta name="layout" content="main">
		<g:set var="entityName" value="${message(code: 'listing.label', default: 'Listing')}" />
		<title><g:message code="default.show.label" args="[entityName]" /></title>
        <g:javascript library="jquery" plugin="jquery"/>
        <g:javascript type="text/javascript">$(document).ready(function(){
                jQuery.ajax({type:'POST', url:'/AuctionHaus/listing/showBids/${listingInstance.id}',success:function(data,textStatus)
                {jQuery('#biddiv').html(data);},
                    error:function(XMLHttpRequest,textStatus,errorThrown){}
            });
        });
        </g:javascript>
        <g:javascript type="text/javascript">$(document).ready(function(){
                jQuery.ajax({type:'POST', url:'/AuctionHaus/listing/showMinimumBid/${listingInstance.id}',success:function(data,textStatus)
                {jQuery('#minbid').html(data);},
                    error:function(XMLHttpRequest,textStatus,errorThrown){}
            });
        });
        </g:javascript>
        <g:javascript>
            function done() {
                $('addBidForm').clearForm();
            }
        </g:javascript>
        <g:javascript type="text/javascript">
                var refreshId = setInterval(function()
                        jQuery.ajax({type:'POST', url:'/AuctionHaus/listing/showBids/${listingInstance.id}',success:function(data,textStatus)
                        {jQuery('#biddiv').html(data);},
                            error:function(XMLHttpRequest,textStatus,errorThrown){}
                        }),5000);
        </g:javascript>
        <g:javascript type="text/javascript">
                var refreshId = setInterval(function()
                        jQuery.ajax({type:'POST', url:'/AuctionHaus/listing/showMinimumBid/${listingInstance.id}',success:function(data,textStatus)
                        {jQuery('#minbid').html(data);},
                            error:function(XMLHttpRequest,textStatus,errorThrown){}
                        }),5000);
        </g:javascript>

        <!--$('#foo').load(("AuctionHaus/listing/showBids/${listingInstance.id}"), function(){
        $('#foo').show();

        jQuery.ajax({type:'POST', url:'/AuctionHaus/listing/showBids/13',success:function(data,textStatus){jQuery('#foo').html(data);},error:function(XMLHttpRequest,textStatus,errorThrown){}});-->

	</head>
	<body>

		<a href="#show-listing" class="skip" tabindex="-1"><g:message code="default.link.skip.label" default="Skip to content&hellip;"/></a>
		<div class="nav" role="navigation">
			<ul>
				<li><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></li>
			</ul>
		</div>

		<div id="show-listing" class="content scaffold-show" role="main">
			<h1><g:message code="default.show.label" args="[entityName]" /></h1>
			<g:if test="${flash.message}">
			<div class="message" role="status">${flash.message}</div>
			</g:if>
            <g:hasErrors bean="${listingInstance}">
                <ul class="errors" role="alert">
                    <g:eachError bean="${listingInstance}" var="error">
                        <li <g:if test="${error in org.springframework.validation.FieldError}">data-field-id="${error.field}"</g:if>><g:message error="${error}"/></li>
                    </g:eachError>
                </ul>
            </g:hasErrors>
            <g:hasErrors bean="${bidInstance}">
                <ul class="errors" role="alert">
                    <g:eachError bean="${bidInstance}" var="error">
                        <li <g:if test="${error in org.springframework.validation.FieldError}">data-field-id="${error.field}"</g:if>><g:message error="${error}"/></li>
                    </g:eachError>
                </ul>
            </g:hasErrors>
			<ol class="property-list listing">

                <g:if test="${listingInstance?.name}">
                    <li class="fieldcontain">
                        <span id="name-label" class="property-label"><g:message code="listing.name.label" default="Name" /></span>

                        <span class="property-value"><g:fieldValue bean="${listingInstance}" field="name"/></span>

                    </li>
                </g:if>

                <g:if test="${listingInstance?.startingBidPrice}">
                    <li class="fieldcontain">
                        <span id="startingBidPrice-label" class="property-label"><g:message code="listing.startingBidPrice.label" default="Starting Bid Price" /></span>

                        <span class="property-value"><g:fieldValue bean="${listingInstance}" field="startingBidPrice"/></span>

                    </li>
                </g:if>

				<!--<g:if test="${listingInstance?.winner}">
				<li class="fieldcontain">
					<span id="winner-label" class="property-label"><g:message code="listing.winner.label" default="Winner" /></span>
					
						<span class="property-value" aria-labelledby="winner-label"><g:link controller="customer" action="show" id="${listingInstance?.winner?.id}">${listingInstance?.winner?.encodeAsHTML()}</g:link></span>
					
				</li>
				</g:if>       -->

                <!--<li class="fieldcontain">
                    <span id="currentBidPrice-label" class="property-label"><g:message code="listing.currentBidPrice.label" default="Current Bid" /></span>
                    <g:if test="${listingInstance?.bids?.size() > 0}">
                        <span class="property-value">${listingInstance?.getCurrentBid()}</span>
                    </g:if>
                    <g:else>
                        <span class="property-value">No Bids</span>
                    </g:else>
                </li>-->


                <g:if test="${listingInstance?.endDateTime}">
                    <li class="fieldcontain">
                        <span id="endDateTime-label" class="property-label"><g:message code="listing.endDateTime.label" default="End Date Time" /></span>

                        <span class="property-value"><g:formatDate date="${listingInstance?.endDateTime}" /></span>

                    </li>
                </g:if>
                <li class="fieldcontain">
                    <span id="endDateTime-label" class="property-label">Minimum Bid</span>

                    <span class="property-value"><div id="minbid"></div> </span>

                </li>

				<g:if test="${listingInstance?.bids}">
				<li class="fieldcontain">
					<span id="bids-label" class="property-label"><g:message code="listing.bids.label" default="Bid History (last 10)" /></span>
						<!--<g:each in="${listingInstance.bids}" var="b">-->
						<!--<span class="property-value" aria-labelledby="bids-label">
                            <br/>Bid: Amount ${b.amount}
                            <a href="/AuctionHaus/bid/show/${b.id}">auctionhaus.Bid : ${b.id}</a>
                            <g:link controller="bid" action="show" id="${b.id}">${b?.encodeAsHTML()}</g:link>
                        </span>
						</g:each>-->
                <!--<g:remoteLink controller="Listing" action="showBids" id="${listingInstance.id}" update="foo">Update Bid</g:remoteLink>-->
                    <div id="biddiv"></div>

				</li>
				</g:if>
			
				<!--<g:if test="${listingInstance?.dateCreated}">
				<li class="fieldcontain">
					<span id="dateCreated-label" class="property-label"><g:message code="listing.dateCreated.label" default="Date Created" /></span>
					
						<span class="property-value" aria-labelledby="dateCreated-label"><g:formatDate date="${listingInstance?.dateCreated}" /></span>
					
				</li>
				</g:if>      -->
			
				<g:if test="${listingInstance?.seller}">
				<li class="fieldcontain">
					<span id="seller-label" class="property-label"><g:message code="listing.seller.label" default="Seller" /></span>
					
						<span class="property-value"><g:link controller="customer" action="show" id="${listingInstance?.seller?.id}">
                            ${listingInstance?.seller?.email?.substring(0,listingInstance?.seller?.email?.indexOf("@"))?.encodeAsHTML()}</g:link></span>
					
				</li>


                <g:if test="${listingInstance?.description}">
                    <li class="fieldcontain">
                        <span id="description-label" class="property-label"><g:message code="listing.description.label" default="Description" /></span>

                            <span class="property-value"><g:fieldValue bean="${listingInstance}" field="description"/></span>

                        </li>
                    </g:if>
				</g:if>

            </ol>
            <sec:ifAllGranted roles="ROLE_USER">
                <g:formRemote name="addBidForm"  url="[controller: 'Bid', action: 'addBidOnListing']" update="saveBidDiv" onSuccess="done()">
                   <g:hiddenField name="listing" value="${listingInstance.id}"/>

                   <ol class="property-list listing">
                       <li class="fieldcontain">
                           <span class="property-label"></span>
                           <span class="property-value"><b>${message(code: 'bid.instructions', default: 'Enter Amount to Bid!')}</b></span>
                       </li>
                       <li class="fieldcontain">
                           <span id="bidAmount-label" class="property-label"><g:message code="bid.amount.label" default="Bid Amount" /></span>
                           <span class="property-value"><g:textField name="amount"/></span>
                       </li>
                       <li class="fieldcontain">
                           <span class="property-label"></span>
                           <span class="property-value"><g:submitButton name="addBid" class="save" value="${message(code: 'button.addBidToListing.label', default: 'Bid')}" /></span>
                       </li>
                       <li class="fieldcontain">
                           <span class="property-label"></span>
                           <span class="property-value"><div id="saveBidDiv"></div></span>
                       </li>
                   </ol>
                </g:formRemote>

            </sec:ifAllGranted>

			<!--<g:form>
				<fieldset class="buttons">
					<g:hiddenField name="id" value="${listingInstance?.id}" />
					<g:link class="edit" action="edit" id="${listingInstance?.id}"><g:message code="default.button.edit.label" default="Edit" /></g:link>
					<g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" />
				</fieldset>
			</g:form> -->
		</div>
	</body>
</html>
